<?php
    
    class Index extends Core{
        
		protected $terminal;
		
		protected $frontSmarty;
		
		public function setPlugIn(){
			return array("page.php");
		}
		
		public function __construct(){
			parent::__construct();
			if(!$_SESSION['terminal']){
				$_SESSION['terminal'] = Terminal::getTerminal();	
			}
			$this->terminal = $_SESSION['terminal'];
			$this->frontSmarty = new Smarty();
			$this->frontSmarty->config_dir      = "./App/common/libs/Config_File.class.php";
			$this->frontSmarty->compile_dir     = "./BlockCompiled";
			$this->frontSmarty->cache_dir       = "./BlockCash";
			$this->frontSmarty->template_dir    = "";
			$this->frontSmarty->caching         = false;
			$this->frontSmarty->left_delimiter  = "<{";
			$this->frontSmarty->right_delimiter = "}>";
			$this->frontSmarty->register_function("block_display", "block_display");
			$this->frontSmarty->register_function("css_tag", "css_tag");
			$this->frontSmarty->register_function("js_tag", "js_tag");
			$this->frontSmarty->register_function("image_tag", "image_tag");
		}
		
		public function Index(){
			$this->frontSmarty->display("Html/HeaderGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/IndexGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/FooterGroup/Index".$this->terminal.".html");
		}
		
		public function Category(){
			$categoryid = intval($_GET['categoryid']);
			$category = DB::fetch_row("select *from `bb_category` as C left join `bb_category_setting` as CS 
			            on `C`.`categoryid`=`CS`.`categoryid` where `C`.`categoryid`='{$categoryid}'");
			$path    = $category['path'];
			$this->frontSmarty->display("Html/{$path}/HeaderGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/{$path}/CategoryGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/{$path}/FooterGroup/Index".$this->terminal.".html");
		}
		
		public function InfoList(){
			$categoryid = intval($_GET['categoryid']);
			$category = DB::fetch_row("select *from `bb_category` as C left join `bb_category_setting` as CS 
			            on `C`.`categoryid`=`CS`.`categoryid` where `C`.`categoryid`='{$categoryid}'");
		//	$model  = ucfirst(strtolower($_GET['model']));
		//	$info_model = DB::fetch_row("select *from `bb_info_model`where `name`='{$model}'");
			$path    = $category['path'];
			$infoSql = "select *from `bb_info` as I left join `bb_info_info` as II on I.`infoid`=II.`infoid` where `I`.`categoryid`='{$categoryid}'";
			$page  = new Page($category['infonum'],$infoSql);
			$infos      = $page->content;
			$page_html  = $page->page_html("?m=Index/InfoList&categoryid={$categoryid}");
			foreach($infos as $key=>$val){
				$infos[$key]['date'] = date("Y-m-d",$val['createtime']);
			}
			$this->frontSmarty->assign("infolist",$infos);
			$this->frontSmarty->assign("page",$page_html);
			$this->frontSmarty->display("Html/{$path}/HeaderGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/{$path}/ListGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/{$path}/FooterGroup/Index".$this->terminal.".html");
		}
		
		public function InfoContent(){
			$categoryid = intval($_GET['categoryid']);
			$category = DB::fetch_row("select *from `bb_category` as C left join `bb_category_setting` as CS 
			            on `C`.`categoryid`=`CS`.`categoryid` where `C`.`categoryid`='{$categoryid}'");
			$path = $category['path'];
			$mid  = $category['mid'];
			$info_model = DB::fetch_row("select *from `bb_info_model` where `mid`='{$mid}'");
			$modelName = $info_model['name'];
			$infoid = $_GET['infoid'];
			$info = DB::fetch_row("select *from `bb_info_{$modelName}` where `infoid`='{$infoid}'");
			$this->frontSmarty->assign("info",$info);
			$this->frontSmarty->display("Html/{$path}/HeaderGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/{$path}/InfoGroup/Index".$this->terminal.".html");
			$this->frontSmarty->display("Html/{$path}/FooterGroup/Index".$this->terminal.".html");
		}
		
    }











?>